package org.lgy.sso_server.manager;

import cn.hutool.http.HttpUtil;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import lombok.extern.slf4j.Slf4j;
import org.lgy.sso_comment.constant.AuthConst;
import org.lgy.sso_server.storage.ClientStorage;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;

@Slf4j
@Component
public class SessionManager {

    @Async
    public void logout(String token) {
        List<String> list = ClientStorage.INSTANCE.get(token);
        if (CollectionUtils.isNotEmpty(list)) {
            HashMap<String, Object> params = new HashMap<>(2);
            params.put(AuthConst.LOGOUT_REQUEST, token);
            list.forEach(url -> {
                log.info("当前退出系统地址：" + url);
                HttpUtil.get(url, params);
            });
        }
    }
}
